package org.shopen.puremvc
{
	import org.puremvc.as3.patterns.facade.Facade;
	import org.puremvc.as3.patterns.observer.Notification;
	import org.shopen.puremvc.controller.notehandlers.CreateProjectCommand;
	import org.shopen.puremvc.controller.notehandlers.HandleCancelCreatingRequestCommand;
	import org.shopen.puremvc.controller.notehandlers.HandleCreatingRequestCommand;
	import org.shopen.puremvc.controller.notehandlers.HandleSavingRequestCommand;
	import org.shopen.puremvc.controller.popuphandlers.HandleAboutRequestCommand;
	import org.shopen.puremvc.controller.popuphandlers.HandleGeneralErrorCommand;
	import org.shopen.puremvc.controller.popuphandlers.HandleHelpRequestCommand;
	import org.shopen.puremvc.controller.startup.StartupCommand;
	import org.shopen.puremvc.controller.statehandlers.spec.HandleCreatingCommand;

	public class ApplicationFacade extends Facade
	{
		public static const NAME : String = "ApplicationFacade";
		
		public static function getInstance() : ApplicationFacade
		{
			if (instance == null)
			{
				instance = new ApplicationFacade();
			}
			return instance as ApplicationFacade;
		}
		
		public function startup(application : ShoPaint) : void
		{
			sendNotification(ApplicationConstants.STARTUP, application);
		}
		
		override public function sendNotification(notificationName:String, body:Object=null, type:String=null):void
		{
			trace(notificationName + " : " + type);
			notifyObservers(new Notification(notificationName, body, type));
		}
		
		override protected function initializeController():void
		{
			super.initializeController();
			registerCommand(ApplicationConstants.STARTUP, StartupCommand);
			
			// popups related commands
			registerCommand(ApplicationConstants.GENERAL_ERROR, HandleGeneralErrorCommand);
			registerCommand(ApplicationConstants.HELP_REQUEST, HandleHelpRequestCommand);
			registerCommand(ApplicationConstants.ABOUT_REQUEST, HandleAboutRequestCommand);
			
			// Creating requests
			registerCommand(ApplicationConstants.CREATING_REQUEST, HandleCreatingRequestCommand);
			registerCommand(ApplicationConstants.CANCEL_CREATING_REQUEST, HandleCancelCreatingRequestCommand);
			registerCommand(ApplicationConstants.CREATE, CreateProjectCommand);
			
			registerCommand(ApplicationConstants.CHS_CREATING_CLOSED, HandleCreatingCommand);
			registerCommand(ApplicationConstants.CHS_CREATING_NEW, HandleCreatingCommand);
			
			// Saving requests
			registerCommand(ApplicationConstants.SAVING_REQUEST, HandleSavingRequestCommand);
			
			// FSM related
			//registerCommand(StateMachine.CHANGED, HandleStateChangedCommand);
		}
	}
}